package com.alibaba.datax.plugin.reader.mysqlreader.controller;

import com.alibaba.datax.plugin.reader.mysqlreader.MysqlReader;
import com.alibaba.fastjson.JSONObject;
import com.health.trans.common.constant.PluginType;
import com.health.trans.common.elements.ColumnCast;
import com.health.trans.common.elements.Record;
import com.health.trans.common.transport.BufferedRecordExchanger;
import com.health.trans.common.transport.channel.Channel;
import com.health.trans.common.transport.channel.memory.MemoryChannel;
import com.health.trans.common.util.ConfigParser;
import com.health.trans.common.util.Configuration;
import com.health.trans.common.util.container.LoadUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;

/**
 * @author nqlz
 */

@RestController
@RequestMapping("/")
public class TestController {

    Configuration configuration = ConfigParser.parse("/home/nqlz/IdeaProjects/data-sync/mysqlreader/src/main/java/com/alibaba/datax/plugin/reader/mysqlreader/controller/jjk.json");
    BufferedRecordExchanger recordSender;

    @PostConstruct
    public void init() {
        Channel channel = new MemoryChannel(configuration);
        recordSender = new BufferedRecordExchanger(channel);
    }

    @RequestMapping("jjk")
    public void jjk() {

        MysqlReader.Task task = new MysqlReader.Task();
        task.init(configuration);
        task.startRead(recordSender);
    }

    @RequestMapping("consume")
    public Object consumer(int index) {
        Record fromReader;
        while ((fromReader = recordSender.getFromReader()) != null) {
            System.err.println(fromReader.getColumn(3));
        }
        return "已消费：" ;
    }
}
